param(
    [string]$Input = "..\td\Sample.td",
    [string]$OutputDir = "..\generated"
)

if (-not (Get-Command llvm-tblgen -ErrorAction SilentlyContinue)) {
    Write-Error "llvm-tblgen not found in PATH."
    exit 1
}

$jsonFile = Join-Path $OutputDir "Records.json"
$recordFile = Join-Path $OutputDir "Records.txt"

if (-not (Test-Path $OutputDir)) {
    New-Item -ItemType Directory -Path $OutputDir | Out-Null
}

Write-Host ">> llvm-tblgen $Input -I ..\td -o $recordFile -print-records"
llvm-tblgen $Input -I ..\td -o $recordFile -print-records

Write-Host ">> llvm-tblgen $Input -I ..\td -o $jsonFile -dump-json"
llvm-tblgen $Input -I ..\td -o $jsonFile -dump-json

Write-Host "Generated record dump at $recordFile and JSON at $jsonFile"
